﻿<navigation:Page x:Class="QSHC.QSchedule.Silverlight.Views.PatientAppointmentPage" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           xmlns:custom="clr-namespace:QSHC.CustomControl;assembly=QSHC.CustomControl"
           xmlns:dataPrimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
           xmlns:vm="clr-namespace:QSHC.QSchedule.Silverlight.ViewModels"
           xmlns:converter="clr-namespace:QSHC.QSchedule.Silverlight.Converters"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           d:DesignWidth="970" d:DesignHeight="600" FontFamily="Tahoma" FontSize="14" Language="th-TH"
           Title="PatientAppointmentPage">
    
    <navigation:Page.Resources>
        <vm:PatientAppointmentViewModel x:Key="patientAppointmentViewModel" />
        <converter:PhysicianToTextConverter x:Key="physicianToTextConverter" />
        <Style x:Key="DataGridColumnHeaderStyle" TargetType="dataPrimitives:DataGridColumnHeader">
            <Setter Property="Foreground" Value="#FF000000"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="IsTabStop" Value="False"/>
            <Setter Property="SeparatorBrush" Value="#FFC9CACA"/>
            <Setter Property="Padding" Value="4"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="dataPrimitives:DataGridColumnHeader">
                        <Grid x:Name="Root">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ColorAnimation Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="(Fill).Color" To="#FF448DCA"/>
                                            <ColorAnimation Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Fill).(GradientStops)[3].Color" To="#7FFFFFFF"/>
                                            <ColorAnimation Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Fill).(GradientStops)[2].Color" To="#CCFFFFFF"/>
                                            <ColorAnimation Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Fill).(GradientStops)[1].Color" To="#F2FFFFFF"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ColorAnimation Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="(Fill).Color" To="#FF448DCA"/>
                                            <ColorAnimation Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Fill).(GradientStops)[0].Color" To="#D8FFFFFF"/>
                                            <ColorAnimation Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Fill).(GradientStops)[1].Color" To="#C6FFFFFF"/>
                                            <ColorAnimation Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Fill).(GradientStops)[2].Color" To="#8CFFFFFF"/>
                                            <ColorAnimation Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Fill).(GradientStops)[3].Color" To="#3FFFFFFF"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="SortStates">
                                    <VisualState x:Name="Unsorted"/>
                                    <VisualState x:Name="SortAscending"/>
                                    <VisualState x:Name="SortDescending"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Rectangle x:Name="BackgroundRectangle" Fill="#FF1F3B53" Stretch="Fill" Grid.ColumnSpan="2"/>
                            <Rectangle x:Name="BackgroundGradient" Stretch="Fill" Grid.ColumnSpan="2">
                                <Rectangle.Fill>
                                    <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0">
                                        <GradientStop Color="#FCFFFFFF" Offset="0.015"/>
                                        <GradientStop Color="#F7FFFFFF" Offset="0.375"/>
                                        <GradientStop Color="#E5FFFFFF" Offset="0.6"/>
                                        <GradientStop Color="#D1FFFFFF" Offset="1"/>
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                            <Rectangle x:Name="verticalSeparator" Fill="{TemplateBinding SeparatorBrush}" VerticalAlignment="Stretch" Width="1" Visibility="{TemplateBinding SeparatorVisibility}" Grid.Column="1"/>
                            <CheckBox x:Name="SelectedAllCheckBox" Content=""  VerticalAlignment="Center" HorizontalAlignment="Center" Loaded="SelectedAllCheckBox_Loaded" Click="SelectedAllCheckBox_Click" Command="{Binding Source={StaticResource patientAppointmentViewModel}, Path=IsSelectedCommand}" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </navigation:Page.Resources>

    <Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource patientAppointmentViewModel}}">
        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Horizontal">
                <custom:WatermarkTextBox Margin="5" Watermark="ค้นหาด้วยชื่อ, นามสกุล, หรือ HN" Text="{Binding Path=SearchText, Mode=TwoWay}" Name="SearchTextBox" Width="150" Height="25" />
                <custom:ThaiDatePicker Name="ScheduleDatePicker" SelectedDate="{Binding SelectedDate, Mode=TwoWay}" VerticalAlignment="Center" Margin="10,0,0,0" Height="25" FirstDayOfWeek="Monday" />

                <TextBlock Text="หน่วยบริการ:" Style="{StaticResource TextBlockStyle}" Margin="5,0,0,0" />
                <ComboBox Width="160" Margin="5,0,0,0" ItemsSource="{Binding Path=Services}" DisplayMemberPath="Name" SelectedItem="{Binding Path=SelectedService, Mode=TwoWay}" Style="{StaticResource ComboBoxStyle}" />

                <TextBlock Text="แพทย์:" Style="{StaticResource TextBlockStyle}" Margin="10,0,0,0" />
                <custom:AutoCompleteComboBox x:Name="PhysicianComboBox" 
                                                     Width="160" 
                                                     MaxDropDownHeight="200" 
                                                     Margin="5,0,0,0" Height="25" FontFamily="Tahoma" FontSize="14" SelectedItem="{Binding Path=SelectedPhysician, Mode=TwoWay}" ItemsSource="{Binding Path=Physicians}">
                    <custom:AutoCompleteComboBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding EmployeeCode, Converter={StaticResource physicianToTextConverter}}" />
                            </StackPanel>
                        </DataTemplate>
                    </custom:AutoCompleteComboBox.ItemTemplate>
                </custom:AutoCompleteComboBox>
                
                <Button Content="Search" Margin="10,0,0,0" Width="75" Command="{Binding Path=SearchCommand}" Style="{StaticResource ButtonStyle}" Name="SearchButton" Click="SearchButton_Click" />
                <Button Content="Reset" Margin="10,0,0,0" Width="75" Command="{Binding ResetCommand}" CommandParameter="{Binding ElementName=ScheduleDatePicker}" Style="{StaticResource ButtonStyle}" />
            </StackPanel>
            <sdk:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Path=Appointments}" Margin="5" IsReadOnly="True" SelectedItem="{Binding SelectedAppointment, Mode=TwoWay}"  Height="400" Name="ScheduleDataGrid">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTemplateColumn Width="30" HeaderStyle="{StaticResource DataGridColumnHeaderStyle}">
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox Name="SelectedCheckBox" HorizontalAlignment="Center" IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"  VerticalAlignment="Center" Command="{Binding Source={StaticResource patientAppointmentViewModel}, Path=IsSelectedCommand}" />
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
                    <sdk:DataGridTextColumn Header="HN" Binding="{Binding HN}" />
                    <sdk:DataGridTemplateColumn Header="ชื่อ-สกุล">
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                    <TextBlock Text="{Binding AppointedPatient.Title}" Margin="4,0,0,0" />
                                    <TextBlock Text="{Binding AppointedPatient.FirstName}" />
                                    <TextBlock Text="  "/>
                                    <TextBlock Text="{Binding AppointedPatient.LastName}" Margin="0,0,4,0" />
                                </StackPanel>
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
                    <sdk:DataGridTextColumn Header="วันที่นัด" Binding="{Binding Path=AppointmentDate, StringFormat=\{0:D\}}" />
                    <sdk:DataGridTextColumn Header="หน่วยบริการ" Binding="{Binding Path=Service.Name}" />
                    <sdk:DataGridTextColumn Header="แพทย์" Binding="{Binding Converter={StaticResource physicianToTextConverter}, Path=Physician, ConverterParameter='short'}" />
                    <sdk:DataGridTextColumn Header="สิทธิ" Binding="{Binding Path=AppointedPatient.Payor}" />
                    <sdk:DataGridTemplateColumn Header="เคยเลื่อนนัด">
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Postpone}" TextAlignment="Center" VerticalAlignment="Center"/>
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
                </sdk:DataGrid.Columns>
            </sdk:DataGrid>
            <StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
                <TextBlock Text="หน่วยบริการ:" Style="{StaticResource TextBlockStyle}" Margin="5,0,0,0" />
                <ComboBox Width="200" Margin="5,0,0,0" ItemsSource="{Binding Path=Services}" DisplayMemberPath="Name" SelectedItem="{Binding Path=SelectedPostponeService, Mode=TwoWay}" Style="{StaticResource ComboBoxStyle}" Name="PostponeLocationComboBox" />

                <TextBlock Text="แพทย์:" Style="{StaticResource TextBlockStyle}" Margin="10,0,0,0" />
                <custom:AutoCompleteComboBox x:Name="PostponePhysicianACCB" 
                                                     ItemsSource="{Binding Path=PostponePhysicians}" Width="200" 
                                                     MaxDropDownHeight="200" 
                                                     Margin="5" Height="25" FontFamily="Tahoma" FontSize="14" SelectedItem="{Binding Path=SelectedPostponePhysician, Mode=TwoWay}" Text="{Binding Path=SelectedPostponePhysicianText, Mode=TwoWay}">
                    <custom:AutoCompleteComboBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding EmployeeCode, Converter={StaticResource physicianToTextConverter}}" />
                            </StackPanel>
                        </DataTemplate>
                    </custom:AutoCompleteComboBox.ItemTemplate>
                </custom:AutoCompleteComboBox>
                <TextBlock Text="เลือกวันที่ :" VerticalAlignment="Center" Margin="5" />
                <custom:ThaiDatePicker x:Name="PostponeScheduleDatePicker" SelectedDate="{Binding Mode=TwoWay, Path=SelectedPostponeDate}" VerticalAlignment="Center" FirstDayOfWeek="Monday" />
                <TextBlock Text="เวลา :" VerticalAlignment="Center" Margin="5" />
                <TextBox Text="{Binding Path=SelectedPostponeTime, Mode=TwoWay}" Height="25" Width="50"/>
                <TextBlock Text="น." VerticalAlignment="Center" Margin="5" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                <Button Content="Button" Height="23" Name="button1" Width="75" Command="{Binding Path=NameCommand}" />
                <Button Content="เลื่อนนัด" Width="80" Command="{Binding PostponeCommand}" Style="{StaticResource ButtonStyle}" Cursor="Hand" Margin="5" />
                <Button Content="ยกเลิกนัด" Width="80" Style="{StaticResource ButtonStyle}" Cursor="Hand" Margin="5" Command="{Binding Path=DeleteCommand}" />
                <Button Content="พิมพ์ใบนัด" Width="80" Command="{Binding PrintAppointmentCardCommand}" Style="{StaticResource ButtonStyle}" Cursor="Hand" Margin="5" />
                <Button Content="พิมพ์รายงาน" Width="100" Style="{StaticResource ButtonStyle}" Margin="5" Command="{Binding Path=PrintReportCommand}" />
            </StackPanel>
        </StackPanel>
    </Grid>

</navigation:Page>
